package com.hfzy.ihk.web.file_upload.conf;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Auther: Administrator
 * @Date: 2019/5/15 16:59
 * @Description:
 */
@Configuration
public class MvcConfig implements WebMvcConfigurer {

    /**
     * 上传录音文件绝对路径
     */
    @Value("${web.upload_path}")
    private String recordFilePath;

    /**
     * 对外访问的url
     */
    @Value("${web.record_file_url}")
    private String  recordFileUrl;

    /**
     * 为上传之后的录音文件添加映射
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /**
         * https://www.ihk.cn:8882/recordsUpload/api/record/RecordFileUrl/RecordFileUrl/OUT/mp3/20190515/ceshi.mp3 -->
         *  file:/cloudcall_file/wxRecordFile/RecordFileUrl/OUT/mp3/20190515/ceshi.mp3
         */
        registry.addResourceHandler(recordFileUrl+"**")
                    .addResourceLocations("file:"+recordFilePath);
    }
}
